﻿using System.Web;

using System.Web.Mvc;
namespace OneWorks.Web.Apps.Controllers
{
    using Extension;
    using Common;
    using Metadata.Enum;

    public class FileController : Controller
    {

        private readonly FileHandle _fileHandle = new FileHandle(); 

        [HttpPost]
        public ContentResult Upload(HttpPostedFileBase bagFile)
        {

            return Content(Newtonsoft.Json.JsonConvert.SerializeObject((_fileHandle.UploadImage(bagFile, ImageUse.All))));
        }

        public FileResult LoginCode()
        {

            Session[Config.LOGINCODE] = Utils.RandomHandle.RandomConfusion(4);
            VerificationCodeHandler handler = new VerificationCodeHandler(new VerificationCodeParameters
                {
                    Code = System.Web.HttpContext.Current.Session[Config.LOGINCODE].ToString(),
                    Type = VerificationCodeType.Confusion
                });
            return handler.GetFileContentResult();
        }
    }
}
